﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminCenter/Admin.master" %>

<%@ Register Src="../module/UpFile.ascx" TagName="UpFile" TagPrefix="inal" %>
<script runat="server">
    private int Item_Id = 0;
    private string Folder = "";
    private int Obj_Typ = 0;
    private DateTime Create_Time;
    private Types types;
    private Text text;
    private Product product;
    private Agents agents;
    private Album album;
    private Links links;
    private Admins admins;
    private Videos video;
    private string[] SizeList = Lang.ShowPublic("SizeList").Split(',');
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Item_Id = Utils.GetQueryString("id", 1);
            Obj_Typ = Utils.GetQueryString("obj_typ", 1);
            UpFile1.Item_Typ = 1;
            switch (Obj_Typ)
            {
                case 1: text = new Text(Item_Id, Folder, false);
                    Create_Time = text.Create_Time;
                    UpFile1.Folder = "TextLogo";
                    UpFile1.Obj_Typ = 1;
                    break;
                case 2: product = new Product(Item_Id);
                    Create_Time = product.Create_Time;
                    UpFile1.Folder = "Product";
                    UpFile1.Obj_Typ = 2;
                    break;
                case 3: agents = new Agents(Item_Id);
                    Create_Time = agents.Create_Time;
                    UpFile1.Folder = "Agents";
                    UpFile1.Obj_Typ = 3;
                    break;
                case 5: types = new Types(Item_Id);
                    Create_Time = types.Create_Time;
                    UpFile1.Folder = "Types";
                    UpFile1.Obj_Typ = 5;
                    break;

                case 7: album = new Album(Item_Id);
                    Create_Time = album.Create_Time;
                    UpFile1.Folder = "Album";
                    UpFile1.Obj_Typ = 7;
                    break;
                case 11: links = new Links(Item_Id);
                    Create_Time = links.Create_Time;
                    UpFile1.Folder = "LinksLogo";
                    UpFile1.Obj_Typ = 11;
                    break;
                case 12: video = new Videos(Item_Id);
                    Create_Time = video.Create_Time;
                    UpFile1.Folder = "VideoLogo";
                    UpFile1.Obj_Typ = 12;
                    break;
                case 31: admins = new Admins(Item_Id);
                    Create_Time = admins.Create_Time;
                    UpFile1.Folder = "admins";
                    UpFile1.Obj_Typ = 31;
                    break;
            }
        }
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../Pulgin/Jcrop/jquery.Jcrop.css" rel="stylesheet" />
    <script src="../Pulgin/Jcrop/jquery.Jcrop.min.js"></script>
    <script type="text/javascript">
        var Item_Time = '<%=Create_Time.ToString("yyyy/MM/dd HH:mm:ss")%>';
        var FileExt = ".jpg";
        /* 封面存储路径 */
        var CoverFoolder = "<%=UpFile1.Folder%>";
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <%=Lang.Show("CoverPage")%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <table class="inputs">
        <tr>
            <td><%=Lang.Show("CoverPage")%> :</td>
            <td><inal:UpFile ID="UpFile1" runat="server" Item_Extension="*.jpg; *.png" Cat_Mode="Cut" /></td>
            <td><q id="file_upload"></q></td>
        </tr>
        <tr>
            <td></td>
            <td colspan="2">
                <a href="javascript:ViewCoverImglist()"><%=Lang.Show("PlotingListView") %></a>
            </td>
        </tr>
    </table>
    <div id="Image_Edit_Area">
    <div id="jcrop_target_Area">
        <img src="" id="jcrop_target" />

        <div class="inline-labels">
            <label>X1
                <input type="text" size="4" id="x1" name="x1" /></label>
            <label>Y1
                <input type="text" size="4" id="y1" name="y1" /></label>
            <label>X2
                <input type="text" size="4" id="x2" name="x2" /></label>
            <label>Y2
                <input type="text" size="4" id="y2" name="y2" /></label>
            <label>W
                <input type="text" size="4" id="w" name="w" /></label>
            <label>H
                <input type="text" size="4" id="h" name="h" /></label>
        </div>
    </div>

    <div id="Prives_Area">
        <div class="prives pri320">
            <img src="" id="preview" />
        </div>

        <h3><%=Lang.Show("TestTitle") %></h3>
        <p><%=Lang.Show("TestTextValue") %></p>
    </div>


    <div id="Pic_Info">
        <div id="Command_Area">
            <div id="Set_Area">
                <button data-status="0" data-value="16/9">16:9</button>
                <button data-status="1" data-value="7/5">7:5</button>
                <button data-status="1" data-value="5/3">5:3</button>
                <button data-status="1" data-value="4/3">4:3</button>
                <button data-status="1" data-value="3/2">3:2</button>
                <button data-status="1" data-value="2/1">2:1</button>
                <button data-status="1" data-value="1/1">1:1</button>
            </div>
            <div id="Size_list">
                <ul>
                    <%foreach (string i in SizeList){ %>
                    <li>
                        <input type="checkbox" name="Size_item" title="" value=""  />
                        <span class="w"><%=i %></span> * <span  class="h"></span> px
                    </li>
                    <%} %>
                </ul>
            </div>
        </div>
        <div class="submit_div">
            <button class="bottom" onclick="BuildThumbnail()"><%=Lang.Show("Submit") %></button>
            <button onclick="ViewCoverImglist()" ><%=Lang.Show("View") %></button></div>
    </div>
    </div>




    <script type="text/javascript">
        var jcrop_api;
        var ratio_width = 1;
        var ratio_height = 1;
        var img_p_width, img_p_height,img_b_width,img_b_height
         
        function jcropLaod() {

            

   
         img_p_width = parseInt($('#preview').css("width").replace("px", "")); /* 原始图片宽度 */
         img_p_height = parseInt($('#preview').css("height").replace("px", "")); /* 原始图片高度 */

        /* 初始化 */
        Bulid_Size(16,9)
        

        
            /*可视化编辑区生成 判断图片是长图还是宽图 */
            if (img_p_width > img_p_height)
                $('#jcrop_target').css("max-width", "100%");
            else
                $('#jcrop_target').css("max-height", "580px");

             img_b_width = parseInt($('#jcrop_target').css("width").replace("px", "")); /* 显示区域的图片宽度 */
             img_b_height = parseInt($('#jcrop_target').css("height").replace("px", ""));/* 显示区域的图片高度 */


            /* 如果图片宽度大于选择区域的图片的宽度，进行比列计算 */
            if (img_p_width > img_b_width) {
                ratio_width = img_b_width / img_p_width;
                ratio_height = img_b_height / img_p_height;

            }
        
       // alert(img_p_width + "\n" + img_p_height + "\n" + img_b_width + "\n" + img_b_height + "\n W比列:" + ratio_width + "\n H比列:" + ratio_height);


        $(function () {
            $('#jcrop_target').Jcrop({
                onChange: showCoords,
                onSelect: showCoords,
                aspectRatio: 16 / 9
            }, function () {
                jcrop_api = this;
            });
        });
        }

        function showCoords(c) {
            updatePreview(c)
            $('#x1').val(Math.round(c.x / ratio_width));
            $('#y1').val(Math.round(c.y / ratio_height));
            $('#x2').val(Math.round(c.x2));
            $('#y2').val(Math.round(c.y2));
            $('#w').val(Math.round(c.w / ratio_width));
            $('#h').val(Math.round(c.h / ratio_height));

        };

        function updatePreview(c) {
            if (parseInt(c.w) > 0) {
                var rx = 320 / c.w;
                var ry = 180 / c.h;

                $("#preview").css("width", Math.round(rx * img_b_width));
                $("#preview").css("height", Math.round(rx * img_b_height));
                $("#preview").css("margin-left", 0 - Math.round(rx * c.x));
                $("#preview").css("margin-top", 0 - Math.round(rx * c.y));
            }
        }
        /* 比列调整 */
        $("#Set_Area").delegate("button", "click", function (e) {
            
            var mew_ratio = $(this).attr("data-value");
            var node_status = parseInt($(this).attr("data-status"));
            
            mew_ratio = mew_ratio.split("/");
            if (node_status == 1) {
                jcrop_api.setOptions({ aspectRatio: parseInt(mew_ratio[0]) / parseInt(mew_ratio[1]) });
                Bulid_Size(parseInt(mew_ratio[0]), parseInt(mew_ratio[1]));
                $(this).attr("data-status", 0);
            }
            else
            {
                jcrop_api.setOptions({ aspectRatio: parseInt(mew_ratio[1]) / parseInt(mew_ratio[0]) });
                Bulid_Size(parseInt(mew_ratio[1]), parseInt(mew_ratio[0]));
                $(this).attr("data-status", 1);
            }

            jcrop_api.focus();
        });

        



        

    </script>
</asp:Content>

